#ifndef __EGG_BLOCK_H__
#define __EGG_BLOCK_H__

#include "Block.hpp"

namespace PocketSurvival
{
    struct EggType
    {
        int32_t eggTypeIndex;
        // 营养价值
        float nutritionalValue;
        // 是否在创造中显示
        bool showEgg;
        // 生成的实体的名称
        std::string entityName;
    };
    
    // 蛋
    class EggBlock : public Block
    {
    public:
        std::vector<EggType> eggTypes;

    public:
        static constexpr int32_t Index()
        {
            return 118;
        }
        virtual int32_t getIndex() override; 
        virtual const std::string &getBlockName() override;
        virtual void initialize() override;
        virtual float getNutritionalValue(int32_t value) override;
        virtual float getSicknessProbability(int32_t value) override;
        virtual int32_t getRotPeriod(int32_t value) override;
        virtual int32_t getDamage(int32_t value) override;
        virtual int32_t setDamage(int32_t value, int32_t damage) override;
        virtual int32_t getDamageDestructionValue(int32_t value) override;
        virtual void getCreativeValues(std::vector<int32_t> &blockVec) override;


        const EggType &getEggType(int32_t data); 

        static inline bool GetIsCooked(int32_t data);
        static inline int32_t SetIsCooked(int32_t data, bool isCooked);
        static inline bool GetIsLaid(int32_t data);
        static inline int32_t SetIsLaid(int32_t data, bool isLaid);
        static inline int32_t SetEggType(int32_t data, int32_t eggTypeIndex);
    };


    inline bool EggBlock::GetIsCooked(int32_t data)
    {
        return (data & 1) != 0;
    }

    inline int32_t EggBlock::SetIsCooked(int32_t data, bool isCooked)
    {
        if (!isCooked)
        {
            return data & -2;
        }
        return data | 1;
    }

    inline bool EggBlock::GetIsLaid(int32_t data)
    {
        return (data & 2) != 0;
    }

    inline int32_t EggBlock::SetIsLaid(int32_t data, bool isLaid)
    {
        if (!isLaid)
        {
            return data & -3;
        }
        return data | 2;
    }

    inline int32_t EggBlock::SetEggType(int32_t data, int32_t eggTypeIndex)
    {
        data &= -65521;
        data |= (eggTypeIndex & 0xFFF) << 4;
        return data;
    }

} // namespace PocketSurvival


#endif
